<?php 

/**
 * CodeRS - Atviras kodas Lietuvai
 * Copyright (C) 2007 CodeRS www.coders.lt info@coders.lt
 * MightMedia TVS
 * logai.php - Svetainės klaidų ir pranešimų administravimas
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 * 
 * Ši programa yra laisva. Jūs galite ją platinti ir/arba modifikuoti
 * remdamiesi Free Software Foundation paskelbtomis GNU Bendrosios
 * Viešosios licencijos sąlygomis: 2 licencijos versija, arba (savo
 * nuožiūra) bet kuria vėlesne versija.
 * 
 * Ši programa platinama su viltimi, kad ji bus naudinga, bet BE JOKIOS
 * GARANTIJOS; be jokios numanomos PERKAMUMO ar TINKAMUMO KONKRETIEMS
 * TIKSLAMS garantijos. Žiūrėkite GNU Bendrąją Viešąją licenciją norėdami
 * sužinoti smulkmenas.
 * 
 * Jūs turėjote kartu su šia programa gauti ir GNU Bendrosios Viešosios
 * licencijos kopija; jei ne - rašykite Free Software Foundation, Inc., 59
 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**/

if ($_SERVER['PHP_SELF'] == __FILE__) { header('location: ?'); exit(); }

if (!ADMIN) { header('location: ?'); exit(); }
?>
		<h2>Svetainės Klaidų Registras - Tavo IP: <font color="red"><?php echo $_SERVER['REMOTE_ADDR'];?></font></h2>
		<p>
		<?php
if (isset($url['o']) && !empty($url['o'])) { 
	switch ($url['o']) {
		case "Veiksmas": {
			$order = "action";
			break;
		}
		case "Nr:": {
			$order = "id";
			break;
		}
		case "Nickas": {
			$order = "nick";
			break;
		}
		case "IP": {
			$order = "ip";
			break;
		}
		default: {
			$order = "id";
			break;
		}
	}
}
else { $order = "id"; }

//trinam irasa
if (isset($url['d']) && isnum($url['d'])) {
	if ($url['d'] == "0" && isset($_POST['ip']) && !empty($_POST['ip']) && $_POST['del_all'] == 'Valyti' && isnum($_POST['ip'])) {
			$sql = $db->uzklausa("DELETE FROM `".LENTELES_PRIESAGA."logai` WHERE `ip` = ".escape($_POST['ip']));
			msg("Išvalyta","Ištryniau visus <b>".long2ip($_POST['ip'])."</b> įrašus"); redirect("?id,46;a,19","meta");
	}
	elseif (!empty($url['d'])) {
		$db->uzklausa("DELETE FROM `".LENTELES_PRIESAGA."logai` WHERE `logai`.`id` = ".escape($url['d'])." LIMIT 1;");
		header("location: ?id,46;a,19");
	}
}
elseif (isset($url['v']) && !empty($url['v']) && isnum($url['v'])) {
	$sql = $db->masyvas($db->uzklausa("SELECT id, INET_NTOA(ip) AS ip, action, time FROM `".LENTELES_PRIESAGA."logai` WHERE id=".escape($url['v'])." LIMIT 1"));
	lentele($sql['ip']." - ".kada($sql['time']),input($sql['action']));
}
else {
		include_once(HOME_DIR."variklis/class/forms_inputs.php");
		//$sql = $db->uzklausa("SELECT id, INET_NTOA(ip) AS ip, action, time FROM `logai` ORDER BY $order DESC LIMIT 0 , 100 ");
		$sql = $db->uzklausa("
		SELECT `".LENTELES_PRIESAGA."logai`.`id`, `".LENTELES_PRIESAGA."logai`.`ip`, `".LENTELES_PRIESAGA."logai`.`action`, INET_NTOA(`".LENTELES_PRIESAGA."logai`.`ip`) AS ip1, `".LENTELES_PRIESAGA."logai`.`time`,
		IF(`".LENTELES_PRIESAGA."users`.`username` <> '', `".LENTELES_PRIESAGA."users`.`username`, 'Svecias') AS nick,
		IF(`".LENTELES_PRIESAGA."users`.`user_id` <> '', `".LENTELES_PRIESAGA."users`.`user_id`, '0') AS nick_id
		FROM `".LENTELES_PRIESAGA."logai` Left Join `".LENTELES_PRIESAGA."users` ON `".LENTELES_PRIESAGA."logai`.`ip` = `".LENTELES_PRIESAGA."users`.`regip`
		ORDER BY $order DESC LIMIT 0 , 100
		");
		if ($db->rows($sql) > 0) {
			$info = array();
			while($row = $db->masyvas($sql)) {
				$info[] = array(
					"Nr:"=>$row['id'],
					"Veiksmas"=> "<a href=\"".url("v,".$row['id']."")."\" title=\"header=[Nr:".$row['id']."] body=[
						<br/>
						Laikas: <b>".$row['time']."</b><br/>
						Kada: <b>".kada($row['time'])."</b><br/>
						IP: <b>".$row['ip1']."</b><hr/>
						Klaida: <i>".wrap1(input($row['action']),50)."</i><br/>
						] cssbody=[sarasas] cssheader=[title] fade=[on]\">".trimlink(input(strip_tags($row['action'])),50)."</a>",
				//"Veiksmas"=>trimlink(input($row['action']),50),
				"IP"=>$row['ip1'],
				"Nickas"=>"<a href='http://www.mrcbug.com/?id,47;m,".$row['nick_id']."'>".$row['nick']."</a> <a href=\"?id,45;n,1;u,".input($row['nick'])."\"><img src=\"images/pm/mail.png\" alt=\"pm\" border=\"0\"/></a>",
				"Kada"=>kada($row['time']),
				"Valdymas"=>"<a href=\"".url("d,".$row['id']."")."\" title='Ištrinti įrašą'><img src=\"images/icons/cross.png\" alt=\"[b]\" border=\"0\" class=\"middle\" /></a> <a href='?id,46;a,6;b,".$row['ip']."' title='Uždrausti vartotoją'><img src=\"images/icons/delete.png\" alt=\"[d]\" border=\"0\" class=\"middle\" /></a>"
				);
			}
			$bla = new Table();
			lentele("Svetaines LOGAI",$bla->render($info));
		} else { msg("Svetainės LOGAI","Šiuo metu neužfiksuota jokių klaidų"); }
		?>
		</p>
		<p>
		<?php
		$sql = $db->uzklausa("SELECT count(*) as viso, ip, INET_NTOA(ip) AS ip1 FROM `".LENTELES_PRIESAGA."logai` GROUP BY ip ORDER BY time DESC");
		if ($db->rows($sql) > 0) {
			while($row = $db->masyvas($sql)) {
				$select[$row['ip']] = $row['ip1']." - ".$row['viso'];
			}
			$nustatymai = array(
				"Form"=>array("action"=>url('d,0'),"method"=>"post","enctype"=>"","id"=>"","class"=>"","name"=>"reg"),
				"Trinti pagal IP:"=>array("type"=>"select","value"=>$select,"selected"=>ip2long($_SERVER['REMOTE_ADDR']),"name"=>"ip"),
				""=>array("type"=>"submit","name"=>"del_all","value"=>"Valyti")
				);
			$bla = new forma();
			echo $bla->form($nustatymai,"Automatinis trinimas/valymas");
		}
		?>
		</p>
	</div>
</div>
<?php } ?>